#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int countSubstrings(string s) {
	int n = s.size();
	vector<vector<bool>> dp(n, vector<bool>(n));
	int ret = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		for (int j = i; i < n; i++)
		{
			if (s[i] == s[j])
				dp[i][j] = i+1<j?dp[i + 1][j - 1]:true;
			if (dp[i][j])
				ret++;
		}
	}
	return ret;
}
string longestPalindrome(string s) {
	int n = s.size();
	vector<vector<bool>> dp(n, vector<bool>(n));
	int begin = 0, lenth = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		for (int j = i; j < n; j++)
		{
			if (s[i] == s[j])
				dp[i][j] = i + 1 < j ? dp[i + 1][j - 1] : true;
			if (dp[i][j] && j - i + 1 > lenth)
			{
				lenth = j - i + 1;
				begin = i;
			}
		}
	}
	return s.substr(begin, lenth);
}
bool checkPartitioning(string s) {
	int n = s.size();
	vector<vector<bool>> dp(n, vector<bool>(n));
	for (int i = n - 1; n >= 0; i--)
	{
		for (int j = i; j < n; j++)
		{
			if (s[i] == s[j])
				dp[i][j] = i + 1 < j ? dp[i + 1][j - 1] : true;
		}
	}
	for (int i = 1; i < n - 1; i++)
	{
		for (int j = i; j < n - 1; j++)
		{
			if (dp[0][i - 1] && dp[i][j] && dp[j + 1][n - 1])
				return true;
		}
	}
	return false;
}
int minCut(string s) {
	int n = s.size();
	vector<vector<bool>> isPal(n, vector<bool>(n));
	for (int i = n - 1; i >= 0; i--)
	{
		for (int j = i; j < n; j++)
		{
			if (s[i] == s[j])
				isPal[i][j] = i + 1 < j ? isPal[i + 1][j - 1] : true;
		}
	}
	vector<int> dp(n);
	for (int i = 0; i < n; i++)
	{
		if (isPal[0][i])
			dp[i] = 0;
		else
		{
			for (int j = 1; j <= n; j++)
			{
				if (isPal[j][i])
					dp[i] = min(dp[i], dp[j] + 1);
			}
		}
	}
	return dp[n-1];
}
int longestPalindromeSubseq(string s) {
	int n = s.size();
	vector<vector<int>> dp(n, vector<int>(n));
	int ret = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		dp[i][i] = 1;
		for (int j = i+1; j < n; j++)
		{
			if (s[i] == s[j])
				dp[i][j] = dp[i + 1][j - 1] + 2;
			else
				dp[i][j] = max(dp[i + 1][j], dp[i][j - 1]);
			ret = max(ret, dp[i][j]);
		}
	}
	return ret;
}
int minInsertions(string s) {
	int n = s.size();
	vector<vector<int>> dp(n, vector<int>(n));
	for (int i = n - 1; i >= 0; i--)
	{
		for (int j = i; j < n; j++)
		{
			if (s[i] == s[j] && i + 1 < j)
				dp[i][j] = dp[i + 1][j - 1];
			else if (s[i] != s[j])
				dp[i][j] = min(dp[i + 1][j], dp[i][j - 1]) + 1;
		}
	}
	return dp[0][n - 1];
}
int main()
{
	return 0;
}